﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Expression.Shapes;
using Microsoft.Expression.Media;
using AssessmentTool.PresentationLogic.Controllers;

namespace AssessmentTool.Controls
{
    public partial class Radar : UserControl
    {
        RadarController controller;
        double angleSpicchio = 0;
        public Radar()
        {
            InitializeComponent();
            controller = new RadarController(this);

            svuota();
            /*
            layoutPath.Start = ((1.0 / 18.0) / 2.0);
            Archi.Children.Add(disegnaArco(Color.FromArgb(255, 255, 0, 0), 6, 0));
            Archi.Children.Add(disegnaArco(Color.FromArgb(255, 0, 255, 0), 7, 4));
            
            for (int i = 0; i < 18; i++)
            {
                aggiungiArcoEsterno("A"+i, Color.FromArgb(255, 255, 0, 0), i);
            }*/
            
        }

        public void svuota()
        {
            Archi.Children.Clear();
            ArchiEsterni.Children.Clear();
            pathListBox.Items.Clear();
        }
        public void inizializza(int numeroSpicchi)
        {
            svuota();
            angleSpicchio = 360 / numeroSpicchi;
            layoutPath.Start = ((1.0 / numeroSpicchi) / 2.0);
        }
        public void disegna()
        {
            
        }

        private Arc disegnaArco(Color color, int livello,int spicchio)
        {
            Arc a = new Arc();
            Ellipse cerchioLivello = (Ellipse)Cerchi.Children[Cerchi.Children.Count - livello];
            a.Height = cerchioLivello.Height;
            a.Width = cerchioLivello.Width;
            a.StrokeThickness =0.5;

            a.ArcThickness = 1;
            a.Fill =new SolidColorBrush(color);
            a.StartAngle = angleSpicchio * spicchio;
            a.EndAngle = a.StartAngle + angleSpicchio;
            a.ArcThicknessUnit = UnitType.Percent;
            a.UseLayoutRounding = false;
            a.Stroke = new SolidColorBrush(Color.FromArgb(255,0,0,0));
            a.Stretch = Stretch.None;
            return a;
        }
        public void aggiungiArco(Color color, int livello, int spicchio)
        {
            Archi.Children.Add(disegnaArco(color, livello, spicchio));
        }

       

        public void aggiungiArcoEsterno(String testo, Color colore, int spicchio)
        {
            Arc c = disegnaArco(colore, 11, spicchio);
            c.StrokeThickness = 0;
            Arc b = disegnaArco(Color.FromArgb(255,255,255,255), 10, spicchio);
            
            TextBlock t = new TextBlock();
            t.Text = testo;

            t.FontFamily=new FontFamily("Verdana");
            t.FontSize=10;
            t.FontWeight = FontWeights.Bold;
            t.Width=20;
            t.Height=15;
            t.HorizontalAlignment=HorizontalAlignment.Center;
            t.VerticalAlignment=VerticalAlignment.Center;
            t.TextAlignment = TextAlignment.Center;
            /*
            double y = 300;

            t.Margin = new Thickness(0, 0, 0, y);
            RotateTransform rt = new RotateTransform();
            rt.Angle = c.StartAngle + (angleSpicchio / 2);
            rt.CenterX = t.Width / 2;
            rt.CenterY = (y/2) + (t.Height/2);
            
            

            if ((rt.Angle < 90) || (rt.Angle > 270))
            {

                t.RenderTransform = rt;
            }
            else
            {
                TransformGroup tg = new TransformGroup();
                
                CompositeTransform ct = new CompositeTransform();
                ct.ScaleY = -1;
                ct.ScaleX = -1;
                
                ct.CenterX = t.Width / 2;
                ct.CenterY = t.Height / 2;
                tg.Children.Add(ct);
                //tg.Children.Add(rt);
                t.RenderTransform = tg;
            }
            
            
            */
            
            
            ArchiEsterni.Children.Add(c);
            ArchiEsterni.Children.Add(b);
            
            pathListBox.Items.Add(t);
            //ArchiEsterni.Children.Add(t);

        }

    }
}
